#!/bin/bash

comps="$1"
scripts="$2"
env=$3
user=${4}

if [ "${comps}" = "" ];
then
echo "Usage: iter.sh <component1 component2> <scripts> <env> <user>"
echo "  Iterate each server and execute the scripts."
echo "	<component1 component2>: Use blank space to seperate the multiple components"
echo "	env: optional. Default env is ec2-cv-prod"
echo "	user: optional.Default user is administrator"
exit
fi

if [ "${user}" = "" ];
then
user=administrator
fi
workdir=./`date '+%ss'`
./prepare.sh "${workdir}" "${scripts}" "$env" "${comps}"
serverfile="${workdir}"/server.txt
sshkeyfile="${workdir}"/ssh_key

for server in `cat ${serverfile}` ; do
echo "INFO:	Working at server - ${server}, user - ${user}, script - ${scripts}"
ssh -i ${sshkeyfile} ${user}@${server} "${scripts}"
done
